package com.yunwaikeji.gy_tool_library.utils.notification;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Build;
import android.util.Log;

public class GYNotificationManager implements GYNotificationInfo {
    private void showErrorLog(String error) {
        Log.e(getClass().getSimpleName(), error);
    }

    private final Context context;
    private final NotificationManager notificationManager;
    private final String channelId;

    public GYNotificationManager(Context context, NotificationManager notificationManager, String channelId) {
        this.context = context;
        this.notificationManager = notificationManager;
        this.channelId = channelId;
    }

    public Notification.Builder getNotificationBuilder() {
        return notificationBuilder;
    }

    private Notification.Builder notificationBuilder;

    public GYNotificationManager setNotificationBuilder(Notification.Builder notificationBuilder) {
        this.notificationBuilder = notificationBuilder;
        return this;
    }

    public int showOfId(int id) {
        if (context == null) {
            showErrorLog(NO_INIT);
            return id;
        }
        if (notificationBuilder == null) {
            showErrorLog("NotificationBuilder为空");
            return id;
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            notificationBuilder.setChannelId(channelId);
        }
        notificationManager.notify(id, notificationBuilder.build());
        return id;
    }
}
